using IcsSEMCtrl.Util;
namespace Lifter.Global.Device
{
    public class PortType
    {
        private int _value;
        private static int _size;
        private static PortType[] _array;
        public static string[] displayStrings;
        public static PortType[] displayValues;
        public static PortType LP;//Loading Port
        public static PortType OP;//Output Port
        public static PortType BP;//Buffer Port
        public static PortType IT_ENUM_MAX;
        static PortType()
        {
            PortType._size = 4;
            PortType._array = new PortType[PortType._size];
            PortType.displayStrings = new string[PortType._size];
            PortType.displayValues = new PortType[PortType._size];
            PortType.LP = new PortType(0);
            PortType.OP = new PortType(1);
            PortType.BP = new PortType(2);
            PortType.IT_ENUM_MAX = new PortType(2147483647);
            PortType.displayStrings[0] = "LP";
            PortType.displayStrings[1] = "OP";
            PortType.displayStrings[2] = "BP";
            PortType.displayValues[0] = PortType.LP;
            PortType.displayValues[1] = PortType.OP;
            PortType.displayValues[2] = PortType.BP;
        }
        public static string ValueToString(PortType val)
        {
            string result;
            switch (val.Value())
            {
                case 0:
                    result = PortType.displayStrings[0];
                    break;
                case 1:
                    result = PortType.displayStrings[1];
                    break;
                case 2:
                    result = PortType.displayStrings[2];
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }
        public static PortType StringToValue(string val)
        {
            PortType result;
            if (Helper.IsNullOrEmpty(val))
            {
                result = PortType.IT_ENUM_MAX;
            }
            else
            {
                for (int i = 0; i < PortType.displayStrings.Length; i++)
                {
                    if (val.Equals(PortType.displayStrings[i]))
                    {
                        result = PortType.displayValues[i];
                        return result;
                    }
                }
                result = null;
            }
            return result;
        }
        public int Value()
        {
            return this._value;
        }
        public static PortType From_Int(int value)
        {
            PortType result;
            if (value >= 0 && value < PortType._size)
            {
                result = PortType._array[value];
            }
            else
            {
                result = PortType.IT_ENUM_MAX;
            }
            return result;
        }
        protected PortType(int value)
        {
            this._value = value;
            if (value >= 0 && value < PortType._size)
            {
                PortType._array[this._value] = this;
            }
        }
        public bool Equals(PortType otherEnum)
        {
            return otherEnum.Value() == this._value;
        }
        public override string ToString()
        {
            return PortType.displayStrings[this._value];
        }
    }
}
